-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Implement a conditional swap #304
base: master
Are you sure you want to change the base?
Conversation
Changes to gas cost
🧾 Summary (20% most significant diffs)
Full diff report 👇
|
Changes to gas cost
🧾 Summary (20% most significant diffs)
Full diff report 👇
|
bytes1 settlementType = settlementData[0]; | ||
bytes memory strategyData = settlementData[1:]; | ||
|
||
uint256 returnedAmount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move declaration into the settlementType == 0x01
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, this should not be changed.
contracts/ConditionalSwap.sol
Outdated
IStrategy(strategy).executeStrategy(order.takerToken, order.makerToken, takerTokenAmount, data); | ||
returnedAmount = order.makerToken.getBalance(address(this)) - makerTokenBalanceBefore; | ||
|
||
if (returnedAmount < minMakerTokenAmount) revert InsufficientOutput(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think compare with makerTokenAmount
instead of minMakerTokenAmount
is more appropriate here.
contracts/ConditionalSwap.sol
Outdated
if (returnedAmount < minMakerTokenAmount) revert InsufficientOutput(); | ||
order.makerToken.transferTo(order.recipient, returnedAmount); | ||
} else { | ||
revert(); // specific the error message1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add error here, debug would be easier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add a new error InvalidSettlementType
for this case.
Snapshot memory recMakerToken = BalanceSnapshot.take({ owner: recipient, token: defaultOrder.makerToken }); | ||
|
||
// craft the `flagAndPeriod` of the defaultOrder for BestBuy case | ||
uint256 flags = 1 << 253; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define flags constant first and use logic OR
here to compose flags
to have better semantic meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
super.setUp(); | ||
} | ||
|
||
function testBestBuyOrder() external { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comments for different scenario requirement and flags to help reader understanding
297b2b5
to
48fbfef
Compare
contracts/ConditionalSwap.sol
Outdated
|
||
_emitConOrderFilled(order, orderHash, takerTokenAmount, returnedAmount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use returnedAmount
in event instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
order.takerTokenAmount, | ||
order.makerToken, | ||
order.makerTokenAmount, | ||
keccak256(order.takerTokenPermit), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EIP712: The dynamic values
bytes
andstring
are encoded as a keccak256 hash of their contents.
fillConOrder
function